package com.baselibrary.libs.View.loading;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.baselibrary.libs.R;
import com.baselibrary.libs.Utils.UtilsMyText.UtilsMyText;
import com.baselibrary.libs.View.baseView.BaseView;


/**
 * Created by Administrator 于萌萌
 * 创建日期: 11:07 . 2017年03月14日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class LoadingView extends BaseView {
    public final static int VISIBLES = 1;
    public final static int GONES = 0;


    private ProgressBar mProgressBar;
    private TextView mHint;

    public LoadingView(Context context) {
        super(context);
    }

    public LoadingView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public int getXml() {
        return R.layout.loadingview_layou;
    }

    @Override
    public void initView(View view) {
        mProgressBar = (ProgressBar)view.findViewById(R.id.progressBar);
        mHint = (TextView)view.findViewById(R.id.hint);


        this.setVisibility(GONE);
        this.setClickable(true);
    }
    ViewCallBack mViewCallBack;

    public interface ViewCallBack {
     void open();
        void closed();
    }
    public void setViewCallBack(ViewCallBack callBack){
        mViewCallBack = callBack;
    }


    public LoadingView setHint(String hint){
        UtilsMyText.setText(mHint,hint);
        return this;
    }
    int status = 0;
    public LoadingView setShowLoading(boolean b){
        if (b){
            this.setVisibility(VISIBLE);
            status = VISIBLES;
            if (null!=mViewCallBack)
                mViewCallBack.open();

        }else{
            this.setVisibility(GONE);
            status = GONES;
            if (null!=mViewCallBack)
                mViewCallBack.closed();
        }
        return this;
    }
    public int isStatus(){

        return status;
    }

}
